[<AutoOpen>]
module Warehouse.SmoExtensions

open System
open Microsoft.SqlServer.Management.Smo
open Microsoft.SqlServer.Management.Common
open System.Configuration
open System.Data.EntityClient
open System.Data.SqlClient

type Server with
    static member FromConfigFile() = 
        let connectionString = ConfigurationManager.ConnectionStrings.["Repository"].ConnectionString
        let efConnectionString = EntityConnectionStringBuilder connectionString
        let sqlConnectionString = efConnectionString.ProviderConnectionString
        let connection = ServerConnection( ConnectionString = sqlConnectionString )
        Server connection

    member this.IsLocal = Environment.MachineName =~ this.NetName
    member this.InitialCatalog = SqlConnectionStringBuilder(this.ConnectionContext.ConnectionString).InitialCatalog